const mongoose = require('mongoose');

const albumSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
    trim: true
  },
  description: {
    type: String,
    trim: true
  },
  user: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: true
  },
  parentAlbum: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Album',
    default: null
  },
  isDeleted: {
    type: Boolean,
    default: false
  },
  deletedAt: {
    type: Date,
    default: null
  },
  createdAt: {
    type: Date,
    default: Date.now
  }
});

// 索引
albumSchema.index({ user: 1, name: 1 }, { unique: true });
albumSchema.index({ isDeleted: 1, deletedAt: 1 });

module.exports = mongoose.model('Album', albumSchema); 